Component({
  properties:{
    time:{
      type:Number,
      value:10
    }
  },
  externalClasses:['count-class'],

 lifetimes:{
  attached(){
    // this.countStart()
    this.startTime()

  }
 },

  methods:{
    countStart() {
      let timer = null
      // 停止定时器
      if (this.data.time === 0) return clearTimeout(timer)
      // 更新渲染
      this.setData({
        time: (this.data.time -= 1),
      })
      // 定时器
      timer = setTimeout(this.countStart.bind(this), 1000)
      // 传递数据到组件外部
      this.triggerEvent('change', this.data.time)
    },
    startTime(){
      let timerr = null
      timerr = setInterval(() => {
        if(this.data.time === 0) return clearInterval(timerr)
        this.setData({
          time:--this.data.time
        })
        this.triggerEvent('change',this.data.time)
      },1000)
    },
    
  },
  
})
